package com.example.smartcity_poverty.ui.AllService.VolunteerService.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import com.example.smartcity_poverty.App.Companion.getToken
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.Repository.api
import com.example.smartcity_poverty.logic.Repository.coroutine
import com.example.smartcity_poverty.logic.util.Util.show
import kotlinx.android.synthetic.main.activity_vt_show.*
import kotlinx.coroutines.Dispatchers

/***
 * 详情页
 */
class VtShowActivity : AppCompatActivity() {

    private val id by lazy { intent.getStringExtra("id")?.toInt() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_vt_show)
        title = "详情页"

        coroutine(Dispatchers.Main) {
            api.getVtDataShow(getToken(), id!!).apply {
                if (this.code == 200) {
                    runOnUiThread {
                        this.data?.let {
                            vtShowTitle.text = it.title
                            vtShowClass.text = "承办单位: ${it.undertaker}"
                            vtShowTime.text = "活动开始时间: ${it.startAt}"
                            vtShowUser.text = "人员要求: ${it.requireText}"
                            vtShowContent.text = "活动详情: ${it.detail}"
                        }
                    }
                } else runOnUiThread { this.msg?.show() }
            }
        }


    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}